package com.wolfden.drugserver.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.wolfden.drugserver.Constants;

public class SpawnCommandManager implements CommandExecutor {

	@SuppressWarnings("null")
	@Override
	public boolean onCommand(CommandSender sender, Command command,
			String label, String[] args) {
		
		Player p = null;
		if (sender instanceof Player)
			p = (Player) sender;
		
		if (command.getName().equalsIgnoreCase("setspawn")) {
			if (p != null) {
				Constants.spawnMap.changeSpawn(p);
				return true;
			} else {
				p.getServer().getLogger().info("Command can only be run by players!");
			}
		} else if (command.getName().equalsIgnoreCase("spawn")) {
			if (p != null) {
				if (Constants.spawnMap.containsPlayer(p)) {
					p.teleport(Constants.spawnMap.getSpawnForPlayer(p));
					return true;
				} else {
					p.sendMessage("You must set a spawn before teleporting to one.");
				}
			}
		}
		return false;
	}

}
